package CoteClient;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;



public class VueConnexion extends Vue{

	
	private JPanel contentPane;
	private JTextField textFieldLogin;
	private JLabel lblPassword;
	private JPasswordField textFieldPassword;
	
	public VueConnexion(Controleur controleur) {

		super(controleur);
		setTitle("Connexion");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);		
		
		Dimension tailleEcran = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
		int hauteur = (int)tailleEcran.getHeight();
		int largeur = (int)tailleEcran.getWidth();
		int x = 464;
		int y = 296;
		setBounds(largeur/2-(x/2), hauteur/2-(y/2), x, y);
		
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		 
		JMenu mnErim = new JMenu("Menu");
		menuBar.add(mnErim);
		
		JMenuItem mntmQuitter = new JMenuItem("Quitter");
		mnErim.add(mntmQuitter);
		
		JMenu mnNewMenu = new JMenu("Indentification");
		menuBar.add(mnNewMenu);
		
		JMenuItem mntmLogin = new JMenuItem("Login");
		mntmLogin.setEnabled(false);
		mnNewMenu.add(mntmLogin);
		
		JMenuItem mntmLogout = new JMenuItem("Logout");
		mntmLogout.setEnabled(false);
		mnNewMenu.add(mntmLogout);
		
		JMenuItem mntmSignUp = new JMenuItem("Sign up");
		mnNewMenu.add(mntmSignUp);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		textFieldLogin = new JTextField();
		textFieldLogin.setBounds(170, 44, 208, 20);
		contentPane.add(textFieldLogin);
		textFieldLogin.setColumns(10);
		
		textFieldPassword = new JPasswordField();
		textFieldPassword.setBounds(170, 77, 208, 20);
		contentPane.add(textFieldPassword);
		
		JLabel lblLogin = new JLabel("Nom de compte");
		lblLogin.setHorizontalAlignment(SwingConstants.RIGHT);
		lblLogin.setBounds(35, 43, 117, 20);
		contentPane.add(lblLogin);
		
		JLabel lblConnectezvous = new JLabel("Connectez-vous :");
		lblConnectezvous.setHorizontalAlignment(SwingConstants.RIGHT);
		lblConnectezvous.setBounds(12, 12, 117, 15);
		contentPane.add(lblConnectezvous);
		
		JLabel lblCrezUnCompte = new JLabel("Créez un compte :");
		lblCrezUnCompte.setHorizontalAlignment(SwingConstants.RIGHT);
		lblCrezUnCompte.setBounds(12, 141, 117, 20);
		contentPane.add(lblCrezUnCompte);
		
		lblPassword = new JLabel("Mot de Passe");
		lblPassword.setHorizontalAlignment(SwingConstants.RIGHT);
		lblPassword.setBounds(35, 79, 117, 15);
		contentPane.add(lblPassword);
		
		JButton btnLogin = new JButton("Connexion");
		btnLogin.setBounds(170, 109, 102, 25);
		btnLogin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getControleur().connexion(textFieldLogin.getText(),textFieldPassword.getText());
				//getControleur().lancerMenu();
			}
		});
		contentPane.add(btnLogin);
		
		JButton btnCancel = new JButton("Quitter");
		btnCancel.setBounds(276, 109, 102, 25);
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getControleur().fermerVue();
			}
		});
		contentPane.add(btnCancel);

		JButton btnInscription = new JButton("Inscription");
		int x1 = btnLogin.getWidth();
		int y1 = btnLogin.getHeight();
		int w1 = btnLogin.getX();
		int w2 = btnCancel.getX();
		int w = ((w2+x1) - (x1 + (w2-w1-x1)/2) - (x1/2));
		btnInscription.setBounds(w, 169, x1, y1);
		btnInscription.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getControleur().inscrireCompte();
			}
		});
		contentPane.add(btnInscription);
		
	}
}
